#pragma

#include <iostream>
#include <unistd.h>

using namespace std;

typedef void (*work_t)();
typedef void (*task_t)();

uint32_t NextTask() // 得到一个任务号
{
    return rand() % 3;
}

void PrintLog()
{
    cout << "prrintf log task" << endl;
}
void ReloadConf()
{
    cout << "reload conf task" << endl;
}
void ConnectMysql()
{
    cout << "connect mysql task" << endl;
}
task_t tasks[3] = {PrintLog, ReloadConf, ConnectMysql}; // 不同的处理函数

void worker()
{
    while (true)
    {
        uint32_t conmmand_code = 0;
        ssize_t n = read(0, &conmmand_code, sizeof(conmmand_code)); // 从 fd = 0 处读到一个命令函数码

        if (n == sizeof(conmmand_code))
        {
            if (conmmand_code >= 3)
                continue;
            tasks[conmmand_code](); // 码有效就执行对应的函数
        }
        cout << "i am worker: " << getpid() << endl;
        sleep(1);
    }
}